﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO.WaiGaoQiao;
using System.Data;

namespace Model.WaiGaoQiao
{
    public class ArticleSelInfo
    {
        /// <summary>
        /// ID
        /// </summary>
        public int ID
        {
            get;
            set;
        }
        /// <summary>
        /// 物品编号
        /// </summary>
        public string ArticleNO
        {
            get;
            set;
        }

        /// <summary>
        /// 物品名称
        /// </summary>
        public string ArticleName
        {
            get;
            set;
        }
        /// <summary>
        /// 物品规格
        /// </summary>
        public string ArticleUnit
        {
            get;
            set;
        }

        /// <summary>
        /// 数量
        /// </summary>
        public int STOCKS_COUNT
        {
            get;
            set;
        }
        /// <summary>
        /// 减去领用后的数量
        /// </summary>
        public int BRING_COUNT
        {
            get;
            set;
        }

        private DataAccessArticleInfoSel dar;


        public ArticleSelInfo()
        {
            dar = new DataAccessArticleInfoSel();
        }
        /// <summary>
        /// 获取所有人员
        /// </summary>
        /// <returns></returns>
        public DataTable GetAllPerson()
        {
            return dar.GetAllPerson().Tables[0];
        }
        /// <summary>
        /// 获取指定日期的数量
        /// </summary>
        /// <param name="dt">指定日期</param>
        /// <param name="id">物品id</param>
        /// <param name="unit">物品规格</param>
        /// <returns></returns>
        public int GetPlanCount(string dt, int id, string unit)
        {
            IList<ArticleSelInfo> invlist = new List<ArticleSelInfo>();
            ArticleSelInfo invinfo;
            DataSet ds = dar.GetPlanCount(dt);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                invinfo = new ArticleSelInfo();
                invinfo.ID = Convert.ToInt32(item["AID"]);
                invinfo.ArticleUnit = item["Article_Unit"].ToString();
                invinfo.BRING_COUNT = Convert.ToInt32(item["Count"]);
                invlist.Add(invinfo);
            }
          IEnumerable<ArticleSelInfo> rtnList=invlist.Where(inv => inv.ID == id).Where(inv => inv.ArticleUnit == unit);
          if (rtnList != null && rtnList.Count() == 1)
          {
              invinfo = (ArticleSelInfo)rtnList.ToList()[0];
              return invinfo.BRING_COUNT;
          }
          else
          {
              return 0;
          }

        }
        /// <summary>
        /// 获取领取信息
        /// </summary>
        /// <returns></returns>
        public DataTable GetInfomation(int pid)
        {
            return dar.GetInfomation(pid).Tables[0];
        }
        /// <summary>
        /// 获取劳保物品的库存数量
        /// </summary>
        /// <returns></returns>
        public int GetArticleInfoSelCount(string condition)
        {
            return dar.GetArticleInfoSelCount(condition);
        }

        /// <summary>
        /// 获取劳保物品库存信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<ArticleSelInfo> SelInventoryInfoSelInfo(int pagesize, int startindex, string strquery)
        {
            IList<ArticleSelInfo> invlist = new List<ArticleSelInfo>();
            ArticleSelInfo invinfo;
            DataSet ds = dar.SelArticleInfoSelInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                invinfo = new ArticleSelInfo();
                invinfo.ID = Convert.ToInt32(item["ID"]);
                invinfo.ArticleNO = item["ArticleNO"].ToString();
                invinfo.ArticleName = item["ArticleName"].ToString();
                invinfo.ArticleUnit = item["Article_Unit"].ToString();
                invinfo.STOCKS_COUNT = Convert.ToInt32(item["STOCKS_COUNT"]);
                invinfo.BRING_COUNT = Convert.ToInt32(item["BRING_COUNT"]);

                invlist.Add(invinfo);
            }
            return invlist;
        }
    }
}
